<html>
<head><meta charset="utf-8"><title>Tracing in rustc · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html">Tracing in rustc</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198545690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198545690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198545690">(May 23 2020 at 18:06)</a>:</h4>
<p>Hello! There's been some discussion on <a class="stream" data-stream-id="144729" href="/#narrow/stream/144729-wg-traits">#wg-traits</a> about introducing <code>tracing</code> into Chalk, which would make it transitive dependency of <code>rustc</code>, I believe. I also believe that this might require a MCP for the introduction of new/different logging dependency. Am I correct? Is the introduction of tracing be something that y'all would be opposed to?</p>
<p>Regardless if an MCP is required, I'd like to put together a small PR (with the intention of discarding it!) where <code>log</code> is replaced with <code>tracing</code> in rustc. There's been a few situations where a drop-in replacement of <code>log</code> with <code>tracing</code> resulted in a non-trivial performance improvements. Off the top of my head, Eliza Weisman observed that replacing <code>log</code> with <code>tracing</code> in <a href="https://github.com/hyperium/h2">h2</a> for <em>fully disabled log statements</em> yielded a p99 performance improvement of 2 ms; dropping from 3ms to 1ms. I'm not sure I expect something as dramatic as this in <code>rustc</code> (given H2 is an interactive system and <code>rustc</code> is batch-optimized...), but measuring the compiler performance impact might be useful.</p>



<a name="198545721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198545721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198545721">(May 23 2020 at 18:07)</a>:</h4>
<p>(Measuring and accepting a change in rustc might allow for less work in Chalk to feature-flag out some of tracing's more advanced macros _and_—this is a big maybe—yield performance improvements in <code>rustc</code>.)</p>



<a name="198546343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198546343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Huey <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198546343">(May 23 2020 at 18:27)</a>:</h4>
<p>It's worth noting that with some (roughly) planned refactoring to Chalk crate structure, tracing probably won't even be a transitive dependency of <code>librustc_middle</code>, only <code>librustc_traits</code></p>



<a name="198547147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198547147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198547147">(May 23 2020 at 18:49)</a>:</h4>
<p>Oh, good to hear. I now realize you mentioned this yesterday, but I didn't process it. Thanks for the correction and sorry for making you repeat it :)</p>



<a name="198798658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198798658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198798658">(May 26 2020 at 18:01)</a>:</h4>
<p><span class="user-mention" data-user-id="198819">@David Barsky</span> one thing to note is that, in rustc anyway, I think logging is compiled out in release builds</p>



<a name="198798685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198798685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198798685">(May 26 2020 at 18:01)</a>:</h4>
<p>in particular, if debug-assertions is not enabled</p>



<a name="198798732"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198798732" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198798732">(May 26 2020 at 18:01)</a>:</h4>
<p>ah, then this will be a no-op. excellent!</p>



<a name="198799249"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198799249" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198799249">(May 26 2020 at 18:06)</a>:</h4>
<p>I would love to have <code>tracing</code> in rustc instead of plain <code>log</code></p>



<a name="198799328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198799328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198799328">(May 26 2020 at 18:06)</a>:</h4>
<p>if we can get more structured logs out, I'm a fan</p>



<a name="198799410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198799410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198799410">(May 26 2020 at 18:07)</a>:</h4>
<p>I mean... as already stated, we can start with a drop-in replacement and then slowly play with the advanced features</p>



<a name="198803565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198803565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198803565">(May 26 2020 at 18:41)</a>:</h4>
<p>Okay, to make sure I understand the conclusions:</p>
<ul>
<li>this <em>won't</em> require feature-flagging out advanced <code>tracing</code> features in Chalk.</li>
<li>adding <code>tracing</code> to rustc <em>will</em> require an MCP?</li>
</ul>



<a name="198805796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/198805796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#198805796">(May 26 2020 at 18:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/131828-t-compiler/topic/Tracing.20in.20rustc/near/198798658">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="198819">David Barsky</span> one thing to note is that, in rustc anyway, I think logging is compiled out in release builds</p>
</blockquote>
<div class="codehilite"><pre><span></span><code>$ echo &quot;fn main() {}&quot; | RUSTC_LOG=trace rustc -
[INFO  rustc_metadata::creader] resolving crate `std`
[INFO  rustc_metadata::creader] falling back to a load
[INFO  rustc_metadata::locator] lib candidate: /home/bjorn/.rustup/toolchains/nightly-2020-05-25-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-265ff16c7b6b86f9.rlib
[...]
[INFO  rustc_codegen_ssa::back::link] linker stderr:

[INFO  rustc_codegen_ssa::back::link] linker stdout:
</code></pre></div>


<p>Info and higher are enabled when debug assertions are disables: <a href="https://github.com/rust-lang/rust/blob/7b73d14b0b35e7b4f79f2d71dc1bbbab31698288/src/librustc_hir/Cargo.toml#L21">https://github.com/rust-lang/rust/blob/7b73d14b0b35e7b4f79f2d71dc1bbbab31698288/src/librustc_hir/Cargo.toml#L21</a></p>



<a name="212739798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212739798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212739798">(Oct 08 2020 at 19:40)</a>:</h4>
<p>With <a href="https://github.com/rust-lang/rust/issues/75143">#75143</a> merged does anything else need to be done before I can start replacing <code>debug</code> with <code>#[instrument]</code> where it's beneficial?</p>



<a name="212739987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212739987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212739987">(Oct 08 2020 at 19:42)</a>:</h4>
<p>Benchmark it on a high traffic function</p>



<a name="212740049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212740049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212740049">(Oct 08 2020 at 19:43)</a>:</h4>
<p>Other than hypothetical perf problems, we can go crazy with tracing now</p>



<a name="212740142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212740142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212740142">(Oct 08 2020 at 19:44)</a>:</h4>
<p>Well. I'm thinking about trait solving, which should be good for perf testing.</p>



<a name="212742058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212742058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212742058">(Oct 08 2020 at 20:01)</a>:</h4>
<p>One thing to consider is also whether to use spans or to use events, as we didn't have this distinction before. I don't know because I haven't tested, but I would assume spans are more expensive</p>



<a name="212971459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212971459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212971459">(Oct 11 2020 at 16:20)</a>:</h4>
<p>[knocks on wood] spans shouldn't be more expensive than events; they're almost the same underlying structure.</p>



<a name="212971481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212971481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> David Barsky <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212971481">(Oct 11 2020 at 16:21)</a>:</h4>
<p>i'd maybe hold of on going wild with <code>#[instrument]</code> until <a href="https://github.com/tokio-rs/tracing/pull/989">https://github.com/tokio-rs/tracing/pull/989</a> lands, if only to reduce refactoring churn</p>



<a name="212973210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Tracing%20in%20rustc/near/212973210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Tracing.20in.20rustc.html#212973210">(Oct 11 2020 at 17:11)</a>:</h4>
<p>Oh nice, that'll make things easier</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>